#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   table_utils.py    
@Contact :   raogx.vip@hotmail.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2021/12/19 下午11:39   gxrao      1.0         None
'''

# import lib


from scrapy.selector import Selector
from utils.text_utils import clean_text

def parse_line_table(table_node):
    result = []
    trs = table_node.xpath("./tr")
    keys = trs[0].xpath("./td/text()").extract()
    for tr in trs[1:]:
        value_values = tr.xpath('./td/text()').extract()
        item = {}
        for key, value in zip(keys, value_values):
            item[clean_text(key)] = clean_text(value)

        result.append(item)
    return result
